package cn.abc.def.controller;

import cn.abc.def.domain.ResponseResult;
import cn.abc.def.service.SpringTransactionalServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 编程式事务。需要注册一个transactionTemplate的bean
 */
@RestController
@RequestMapping("/transactional")
public class SpringTransactionalController {

    @Resource
    private SpringTransactionalServiceImpl springTransactionalService;

    @RequestMapping("/test")
    public ResponseResult test() {
        try {
            return springTransactionalService.test();
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(-1, "failed");
        }
    }
}
